<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <!-- 组件实例对象 -->
      <cpn></cpn>
      <cpn></cpn>
      <cpn></cpn>
    </div>

    <template id="cpn">
      <div>
        <h2>当前计数：{{counter}}</h2>
        <button @click="increment">+</button>
        <button @click="decrement">-</button>
      </div>
    </template>

    <script src="../js/vue.js"></script>

    <script>
      const obj = {
        counter: 0,
      };
      // 2.注册组件
      Vue.component("cpn", {
        template: "#cpn",
        // data() {
        //   return {
        //     counter: 0,
        //   };
        // },
        // 会出现连锁反应
        data() {
          return obj;
        },
        methods: {
          increment() {
            this.counter++;
          },
          decrement() {
            this.counter--;
          },
        },
      });

      const app = new Vue({
        el: "#app",
        data: {
          message: "你好",
        },
      });
    </script>
  </body>
</html>
